package cl.whyem.testsutilityproject.recursion;

import java.util.Arrays;
import java.util.List;

public class Recursividad {

    public static void main(String... args) {
        System.out.println("MAX -> " + new Recursividad().max(Arrays.asList(1, 500, 99, 2, 199, 8)));
    }

    private Integer max(List<Integer> list) {
        System.out.println("Args recursivo -> " + list);
        if (list.size() == 1) {
            return list.get(0);
        } else {
            return findMax(list.get(0), max(list.subList(1, list.size())));
        }
    }

    private Integer findMax(Integer x, Integer y) {
        System.out.println("(x-y) Comparando -> " + x + " - " + y);
        return x > y ? x : y;
    }

}
